

package com.example.android_wx.activity;

        import android.content.Intent;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.Toast;

        import androidx.annotation.Nullable;
        import androidx.appcompat.widget.AppCompatEditText;
        import androidx.appcompat.widget.AppCompatImageView;
        import androidx.appcompat.widget.AppCompatTextView;

        import com.example.android_wx.R;
        import com.example.android_wx.base.App;
        import com.example.android_wx.base.BaseActivity;
        import com.example.android_wx.fragment.MineFragment;
        import com.example.android_wx.http.BaseCallBack;
        import com.example.android_wx.http.HttpHelp;
        import com.jeremyliao.liveeventbus.LiveEventBus;

public class ModifyMobileActivity extends BaseActivity {
    private AppCompatImageView backImageView;
    private AppCompatEditText newMobileEditText,olMobileEditText;
    private AppCompatTextView modifyTextView;
    private View newMobileView,olMobileView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_modify_mobile);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {

        backImageView = findViewById(R.id.backImageView);
        modifyTextView = findViewById(R.id.modifyTextView);
        newMobileEditText = findViewById(R.id.newMobileEditText);
        olMobileEditText = findViewById(R.id.olMobileEditText);
        newMobileView = findViewById(R.id.newMobileView);
        olMobileView = findViewById(R.id.olMobileView);

    }

    @Override
    public void initEvent() {


        backImageView.setOnClickListener(view -> finish());

        olMobileView.setOnFocusChangeListener((view, b) -> {
            if (b) {
                olMobileView.setBackgroundResource(R.color.primary);
                newMobileView.setBackgroundResource(R.color.textHint);
            }
        });

        newMobileView.setOnFocusChangeListener((view, b) -> {
            if (b) {
                olMobileView.setBackgroundResource(R.color.textHint);
                newMobileView.setBackgroundResource(R.color.primary);
            }
        });



        modifyTextView.setOnClickListener(v -> {

            String newMobile = newMobileEditText.getText().toString();
            String olMobile = olMobileEditText.getText().toString();
            if (newMobile.isEmpty()&&olMobile.isEmpty()){
                Toast.makeText(this, "请输入旧手机号码和新手机号码", Toast.LENGTH_SHORT).show();
                return;
            }

            modifyTextView.setEnabled(false);//禁用按钮
            modifyTextView.setText("正在修改...");//修改按钮文字

            HttpHelp.get().ready("member", "modifyMobile")
                    .add("newnumber", newMobile)
                    .add("olnumber",olMobile)
                    .get(new BaseCallBack() {
                        @Override
                        public void onSuccess(String data) {

                            App.get().getMemberData().setMemberMobile(newMobile);
                            Toast.makeText(ModifyMobileActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                            finish();
                        }

                        @Override
                        public void onFailure(String reason) {
                            Toast.makeText(ModifyMobileActivity.this, reason, Toast.LENGTH_SHORT).show();
                            modifyTextView.setEnabled(true);//启用按钮
                            modifyTextView.setText("保存");//修改按钮文字
                        }
                    });


        });



    }
}
